/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package qual2009;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import static chanlib.Chan_IO.*;

/**
 * @author robit
 */
public class AlienLanguage{
    /*
      All neccesary to be defined
      including:
      variable, inner class
    */
    // static int A;
    // static void B();
    // static class C
    static int L,D,N;
    static String vocabs[];
    /*
       One calculation fits all of the cases.
    */
    static void preReckon(){
        return;
    }

    /*
      calculate the answer
    */
    private static void reckon(int line) {
        String rawword=String();
        Set<Integer> test[]=new Set[L];
        int cur=0;boolean orloop=false;
        for(int j=0;j<rawword.length();j++){            
            if(rawword.charAt(j)>='a'&&rawword.charAt(j)<='z'){
                if(orloop){
                    test[cur].add((int)rawword.charAt(j));
                }else{
                    test[cur]=new HashSet<Integer>();
                    test[cur].add((int)rawword.charAt(j));
                    cur++;
                }                
            }else if(rawword.charAt(j)=='('){
                test[cur]=new HashSet<Integer>();
                orloop=true;
            }else if(rawword.charAt(j)==')'){
                cur++;
                orloop=false;
            }
        }
        boolean counter[]=new boolean[D];
        for(int i=0;i<D;i++){
            counter[i]=true;
        }

        for(int j=0;j<L;j++)// fixing index
        for(int i=0;i<D;i++)// dics entry
            if(!test[j].contains((int)vocabs[i].charAt(j)))
                counter[i]=false;

        int ans=0;
        for(int i=0;i<D;i++){
            if(counter[i])ans++;
        }

        String output=String.format("Case #%d: %d",line,ans);
        writeln(output, OUTFILE);
//        for(int l=0;l<L;l++){
//
//            for(int c:test[l]){
//                System.out.print((char)c);
//            }
//            System.out.print(',');
//        }
//        println("");


        //println(output);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        /*
           Pre-computing for all cases
        */

        // Just in case!
        //preReckon();
        //while((char)read()!='P');

        /*
          Input-output
        */
        boolean test=false;
        boolean small=false;
        String prob="A";
        String filename;
        if(test) filename="test";
        else{
            if(small) filename=prob+"-small-practice";
            else filename=prob+"-large-practice";
        }
        try {
            /*
               Init IO,plus determination of input line number
             */
            initIO(filename);
            L=Int();D=Int();N=Int();

            vocabs=new String[D];
            for(int i=0;i<D;i++)
                vocabs[i]=String();

            for (int i = 1; i <=N; i++) {
                reckon(i);
            }
        } finally {
            endIO();
        }
    }

}
